<template>
  <div class="mine">
    <div class="top">
      <img :src="userInfo.photo" alt="" />
      <div>
        <div class="name" style="margin-bottom: 8px;">{{ userInfo.name }}</div>
        <div class="time" style="text-align: center;">
          {{ userInfo.birthday }}
        </div>
      </div>
    </div>
    <div class="middle">
      <div class="item">
        <van-icon name="newspaper-o" />
        <h3>我的作品</h3>
      </div>
      <div class="item">
        <van-icon name="goods-collect-o" />
        <h3>我的收藏</h3>
      </div>
      <div class="item">
        <van-icon name="browsing-history-o" />
        <h3>阅读历史</h3>
      </div>
    </div>
    <div class="bottom">
      <van-cell-group>
        <van-cell
          @click="toEdit"
          icon="user-o"
          title="编辑资料"
          is-link
        ></van-cell>
        <van-cell icon="envelop-o" title="小智同学" is-link to="/layout/chat" />
        <van-cell icon="setting-o" title="系统设置" is-link />
        <van-cell
          icon="warning-o"
          title="退出登录"
          is-link
          @click="exit"
        ></van-cell>
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  created () {
    this.$store.dispatch('getUserInfo')
  },
  computed: {
    ...mapState(['userInfo'])
  },
  methods: {
    toEdit () {
      this.$router.push('/layout/edit')
    },
    exit () {
      this.$dialog
        .confirm({
          title: '提示',
          message: '确定不是手滑？'
        })
        .then(() => {
          this.$store.commit('logout')
        })
        .catch(() => {})
    }
  }
}
</script>

<style lang="less" scoped>
.top {
  background-color: #3296fa;
  height: 150px;
  display: flex;
  align-items: center;
  img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin: 0 15px 0 30px;
  }
  .name {
    font-size: 20px;
    font-weight: normal;
    color: white;
  }
  .time {
    background-color: white;
    color: #3296fa;
  }
}
.middle {
  display: flex;
  justify-content: space-around;
  .item {
    text-align: center;
    .van-icon {
      font-size: 30px;
      padding: 10px 0;
    }
    h3 {
      font-weight: normal;
    }
    &:nth-child(1) {
      .van-icon {
        color: #8daaff;
      }
    }
    &:nth-child(2) {
      .van-icon {
        color: #ff3800;
      }
    }
    &:nth-child(3) {
      .van-icon {
        color: #ffb45a;
      }
    }
  }
}
.bottom {
  margin-top: 15px;
}
</style>
